<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>One to One - Foreign Key Mapping Source</title>
</head>
<body>
  <pre class="brush: java">
// Employee.java Source    
//Package declaration and imports ommited for brevity
@Entity(name="OtoFkEmployee") @Table(name = "oto_fk_employee")
public class Employee {
	
	private int id;
	private String name;
	private Desk desk;
	
	public Employee() {}

	public Employee(String name, Desk desk) {
		this.name = name;
		this.desk = desk;
	}

	@Id @GeneratedValue
	public int getId() {
		return id;
	}
	
	private void setId(int id) {
		this.id = id;
	}
	
	@Column(nullable = false, length = 30)
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	@OneToOne @JoinColumn(name = "desk_id", unique = true)
	public Desk getDesk() {
		return desk;
	}

	public void setDesk(Desk desk) {
		this.desk = desk;
	}
}

// Desk.java Source    
//Package declaration and imports ommited for brevity
@Entity @Table(name = "oto_fk_desk")
public class Desk {

	private int id;
	private String number;
	
	public Desk() {}
	
	public Desk(String number) {
		this.number = number;
	}

	@Id() @GeneratedValue @Column(name="desk_id")
	public int getId() {
		return id;
	}
	
	private void setId(int id) {
		this.id = id;
	}

	@Column(nullable = false, length = 10)
	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}
}
  </pre>
</body>
</html>
